mirror your GitHub repos to tangled.org automatically
1import { and, eq } from 'drizzle-orm'
2import { repoMapping } from '#server/db/schema'
3import { useDb } from '#server/utils/db'
4import { requireSessionAndMappingId } from '#server/utils/repo-route'
5
6/** Clear `disabledAt`, resuming sync for this mapping. */
7export default defineEventHandler(async event => {
8 const { session, mappingId } = await requireSessionAndMappingId(event)
9
10 const db = useDb()
11 const updated = await db.update(repoMapping)
12 .set({ disabledAt: null, updatedAt: new Date() })
13 .where(and(
14 eq(repoMapping.id, mappingId),
15 eq(repoMapping.installationId, session.installationId),
16 ))
17 .returning({ id: repoMapping.id })
18 if (updated.length === 0) {
19 throw createError({ statusCode: 404, statusMessage: 'mapping not found' })
20 }
21 return { ok: true }
22})